var createAddForm = function(selNode)
{	
	var textAreaTitle = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'title',
		fieldLabel: 'title',
		allowBlank: false,
		anchor    : '100%'	
	});

	var textAreaEmail = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'email',
		fieldLabel: 'email',
		allowBlank: true,
		anchor    : '100%'		
	});
	
	var textAreaName = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'name',
		fieldLabel: 'name',
		allowBlank: false,
		anchor    : '100%'		
	});
	
	var birthDateField = new Ext.form.DateField({
		xtype: 'Datefield',
		id: 'birthDate',
		fieldLabel: 'BirthDate',
		allowBlank:true,
		anchor: '100%'		
	});
	
	var hiredDateField = new Ext.form.DateField({
		xtype: 'Datefield',
		id: 'hiredDate',
		fieldLabel: 'HiredDate',
		allowBlank:true,
		anchor: '100%'		
	});
	
	var selNodePath = selNode.getPath();
	var treePanel = Ext.getCmp('companyTreePanel');
	
	if (selNode.id =='CompanyTreeRoot') {
		var aItems = [textAreaTitle, textAreaEmail];
		var wTitle = "Add new Division";
	}
	else if (selNode.id.match('Division')) { 
		var aItems = [textAreaTitle, textAreaEmail];
		var wTitle = "Add new Project";
	}
	else if (selNode.id.match('Project')) {
		var aItems = [textAreaName,textAreaEmail,birthDateField,hiredDateField];
		var wTitle = "Add new Person";
	}
    
    var form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 55,
        defaultType: 'textfield',
        items: aItems
    });

    var window = new Ext.Window({
        title: wTitle,
        width: 400,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,

        buttons: [{
        	text: 'Add',
        	handler: function() {
        		form.getForm().submit({
        			url : 'distributor/addElement',
        			params : {
        				parentNode : selNode.id
        			},
        			waitTitle: 'please wait...',
        			waitMsg: 'wait...',
        			success: function(form, action) {
        				window.close();	                	
        				root = Ext.getCmp('companyTreePanel').getRootNode();
        				root.reload();
        				treePanel.expandPath(selNodePath);
        			},
        			failure: function(form, action) {
        				Ext.Msg.alert('An error occured with the server.');
        			}
        		});
        	}
        }]
    });

    window.show();
};